package org.niceHome.base.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.niceHome.base.BaseMapper;
import org.niceHome.util.CastUtil;

import javax.management.relation.Role;
import java.util.List;
import java.util.Map;

public abstract class BaseServiceImpl<T> {

    public abstract BaseMapper<T> getBaseMapper();

    public void insert(T role){
        getBaseMapper().insert(role);
    }
    public void delete(Long id){
        getBaseMapper().delete(id);
    }
    public void update(T role){
        getBaseMapper().update(role);
    }
    public T getById(Long id){
        return getBaseMapper().getById(id);
    }
    public PageInfo<T> findPage(Map<String,Object> filters){
        int pageNum = CastUtil.castInt(filters.get("pageNum"), 1);
        int pageSize = CastUtil.castInt(filters.get("pageSize"), 7);
        PageHelper.startPage(pageNum,pageSize);
        Page<T> page = getBaseMapper().findPage(filters);
        return new PageInfo<>(page);
    }

    public List<T> findAll() {
        return getBaseMapper().findAll();
    }
}


